import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/antd_icons.dart';
import 'package:meal/constant/fonts.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';
import 'package:url_launcher/url_launcher.dart';

///
/// 帮助中心
///
class HelpCenter extends StatefulWidget {
  const HelpCenter({Key? key}) : super(key: key);

  @override
  State<HelpCenter> createState() => _HelpCenterState();
}

class _HelpCenterState extends State<HelpCenter> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
      appBar: ToolsUtils.getDefaultBrnAppBar('帮助中心'),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              margin: const EdgeInsets.symmetric(
                  horizontal: Sizes.default15, vertical: Sizes.default10),
              padding: const EdgeInsets.all(Sizes.default15),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default10)),
              child: ListBody(
                children: [
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: const EdgeInsets.only(top: Sizes.default5, bottom: Sizes.default20),
                    child: Text('我的服务',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default15,
                            color: ColorsUtils.color333,
                            fontWeight: Fonts.w7)),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    child: Wrap(
                      spacing: Sizes.default15,
                      crossAxisAlignment: WrapCrossAlignment.center,
                      children: [
                        SizedBox(
                          width: 86,
                          child: Column(
                            children: [
                              Container(
                                alignment: Alignment.center,
                                child: ToolsUtils.getUrlSvg(
                                    'https://cdn7.axureshop.com/demo/1525603/images/帮助中心/u11197.svg',
                                    width: 26,
                                    height: 26),
                              ),
                              Container(
                                margin: const EdgeInsets.only(top: Sizes.default10),
                                child: Text(
                                  '意见反馈',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: Sizes.default13, color: ColorsUtils.color000),
                                ),
                              )
                            ],
                          ),
                        ),
                        InkWell(
                          onTap: () {
                            Get.toNamed(RouteGet.userHelpChat);
                          },
                          child: SizedBox(
                            width: 86,
                            child: Column(
                              children: [
                                Container(
                                  alignment: Alignment.center,
                                  child: ToolsUtils.getUrlSvg(
                                      'https://cdn7.axureshop.com/demo/1525603/images/帮助中心/u11200.svg',
                                      width: 26,
                                      height: 26),
                                ),
                                Container(
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '在线客服',
                                    style: StylesUtils.customTextStyle(
                                        fontSize: Sizes.default13, color: ColorsUtils.color000),
                                  ),
                                )
                              ],
                            ),
                          ),
                        ),
                        InkWell(
                          onTap: callMobile,
                          child: SizedBox(
                            width: 86,
                            child: Column(
                              children: [
                                Container(
                                  alignment: Alignment.center,
                                  child: ToolsUtils.getUrlSvg(
                                      'https://cdn7.axureshop.com/demo/1525603/images/帮助中心/u11223.svg',
                                      width: 26,
                                      height: 26),
                                ),
                                Container(
                                  margin: const EdgeInsets.only(top: Sizes.default10),
                                  child: Text(
                                    '电话客服',
                                    style: StylesUtils.customTextStyle(
                                        fontSize: Sizes.default13, color: ColorsUtils.color000),
                                  ),
                                )
                              ],
                            ),
                          ),
                        )
                      ],
                    ),
                  )
                ],
              ),
            ),
            Container(
              margin: const EdgeInsets.only(left: Sizes.default15, right: Sizes.default15),
              padding: const EdgeInsets.all(Sizes.default15),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default10)),
              child: ListBody(
                children: [
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: const EdgeInsets.only(top: Sizes.default5, bottom: Sizes.default20),
                    child: Text('常见问题',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default15,
                            color: ColorsUtils.color333,
                            fontWeight: Fonts.w7)),
                  ),
                  GFAccordion(
                      margin: EdgeInsets.zero,
                      titleChild: Text('账号',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default16, color: ColorsUtils.color000)),
                      titlePadding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                      contentChild: ListBody(
                        children: [
                          Container(
                            alignment: Alignment.centerLeft,
                            margin: const EdgeInsets.symmetric(vertical: Sizes.default15),
                            child: Text.rich(TextSpan(children: [
                              WidgetSpan(
                                child: ToolsUtils.getUrlSvg(
                                    'https://cdn7.axureshop.com/demo/1525603/images/帮助中心/u11207.svg',
                                    width: 15,
                                    height: 15),
                                alignment: PlaceholderAlignment.middle,
                              ),
                              TextSpan(
                                  text: '如何修改店铺名',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color000, fontSize: Sizes.default15))
                            ])),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            margin: const EdgeInsets.only(bottom: Sizes.default8),
                            child: Text('方法：点击个人中心_店铺信息，修改店铺名称提交，提交后等待审核',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            child: Text('审核时效：工作时间（9:00-18:30）正常24小时内审核完毕',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            margin: const EdgeInsets.symmetric(vertical: Sizes.default15),
                            child: Text.rich(TextSpan(children: [
                              WidgetSpan(
                                child: ToolsUtils.getUrlSvg(
                                    'https://cdn7.axureshop.com/demo/1525603/images/帮助中心/u11207.svg',
                                    width: 15,
                                    height: 15),
                                alignment: PlaceholderAlignment.middle,
                              ),
                              TextSpan(
                                  text: '修改登录密码',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color000, fontSize: Sizes.default15))
                            ])),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            child: Text('点击我的_头像_修改登录密码，输入旧密码与新密码即可。',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                          ),
                        ],
                      ),
                      expandedTitleBackgroundColor: Colors.transparent,
                      collapsedTitleBackgroundColor: Colors.transparent,
                      contentBackgroundColor: Colors.transparent,
                      contentPadding: EdgeInsets.zero,
                      collapsedIcon: Icon(
                        AntdIcons.down,
                        color: ColorsUtils.parseColorFromHexString(ColorsUtils.color999),
                        size: Sizes.default15,
                      ),
                      expandedIcon: Icon(AntdIcons.up,
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.color000),
                          size: Sizes.default15)),
                  GFAccordion(
                      margin: EdgeInsets.zero,
                      titleChild: Text('订单',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default16, color: ColorsUtils.color000)),
                      titlePadding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                      contentChild: ListBody(
                        children: [
                          Container(
                            alignment: Alignment.centerLeft,
                            margin: const EdgeInsets.symmetric(vertical: Sizes.default15),
                            child: Text.rich(TextSpan(children: [
                              WidgetSpan(
                                child: ToolsUtils.getUrlSvg(
                                    'https://cdn7.axureshop.com/demo/1525603/images/帮助中心/u11207.svg',
                                    width: 15,
                                    height: 15),
                                alignment: PlaceholderAlignment.middle,
                              ),
                              TextSpan(
                                  text: '如何修改店铺名',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color000, fontSize: Sizes.default15))
                            ])),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            margin: const EdgeInsets.only(bottom: Sizes.default8),
                            child: Text('方法：点击个人中心_店铺信息，修改店铺名称提交，提交后等待审核',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            child: Text('审核时效：工作时间（9:00-18:30）正常24小时内审核完毕',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            margin: const EdgeInsets.symmetric(vertical: Sizes.default15),
                            child: Text.rich(TextSpan(children: [
                              WidgetSpan(
                                child: ToolsUtils.getUrlSvg(
                                    'https://cdn7.axureshop.com/demo/1525603/images/帮助中心/u11207.svg',
                                    width: 15,
                                    height: 15),
                                alignment: PlaceholderAlignment.middle,
                              ),
                              TextSpan(
                                  text: '修改登录密码',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color000, fontSize: Sizes.default15))
                            ])),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            child: Text('点击我的_头像_修改登录密码，输入旧密码与新密码即可。',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                          ),
                        ],
                      ),
                      expandedTitleBackgroundColor: Colors.transparent,
                      collapsedTitleBackgroundColor: Colors.transparent,
                      contentBackgroundColor: Colors.transparent,
                      contentPadding: EdgeInsets.zero,
                      collapsedIcon: Icon(
                        AntdIcons.down,
                        color: ColorsUtils.parseColorFromHexString(ColorsUtils.color999),
                        size: Sizes.default15,
                      ),
                      expandedIcon: Icon(AntdIcons.up,
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.color000),
                          size: Sizes.default15)),
                  GFAccordion(
                      margin: EdgeInsets.zero,
                      titleChild: Text('银行卡',
                          style: StylesUtils.customTextStyle(
                              fontSize: Sizes.default16, color: ColorsUtils.color000)),
                      titlePadding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                      contentChild: ListBody(
                        children: [
                          Container(
                            alignment: Alignment.centerLeft,
                            margin: const EdgeInsets.symmetric(vertical: Sizes.default15),
                            child: Text.rich(TextSpan(children: [
                              WidgetSpan(
                                child: ToolsUtils.getUrlSvg(
                                    'https://cdn7.axureshop.com/demo/1525603/images/帮助中心/u11207.svg',
                                    width: 15,
                                    height: 15),
                                alignment: PlaceholderAlignment.middle,
                              ),
                              TextSpan(
                                  text: '如何修改店铺名',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color000, fontSize: Sizes.default15))
                            ])),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            margin: const EdgeInsets.only(bottom: Sizes.default8),
                            child: Text('方法：点击个人中心_店铺信息，修改店铺名称提交，提交后等待审核',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            child: Text('审核时效：工作时间（9:00-18:30）正常24小时内审核完毕',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            margin: const EdgeInsets.symmetric(vertical: Sizes.default15),
                            child: Text.rich(TextSpan(children: [
                              WidgetSpan(
                                child: ToolsUtils.getUrlSvg(
                                    'https://cdn7.axureshop.com/demo/1525603/images/帮助中心/u11207.svg',
                                    width: 15,
                                    height: 15),
                                alignment: PlaceholderAlignment.middle,
                              ),
                              TextSpan(
                                  text: '修改登录密码',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color000, fontSize: Sizes.default15))
                            ])),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            child: Text('点击我的_头像_修改登录密码，输入旧密码与新密码即可。',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                          ),
                        ],
                      ),
                      expandedTitleBackgroundColor: Colors.transparent,
                      collapsedTitleBackgroundColor: Colors.transparent,
                      contentBackgroundColor: Colors.transparent,
                      contentPadding: EdgeInsets.zero,
                      collapsedIcon: Icon(
                        AntdIcons.down,
                        color: ColorsUtils.parseColorFromHexString(ColorsUtils.color999),
                        size: Sizes.default15,
                      ),
                      expandedIcon: Icon(AntdIcons.up,
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.color000),
                          size: Sizes.default15)),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  void callMobile() async {
    final dialog = BrnDialog(
        verticalDivider: const VerticalDivider(
          width: 1.0,
          color: Colors.black,
        ),
        divider: const Divider(
          height: 1.0,
          color: Colors.black,
        ),
        contentWidget: ListBody(
          children: [
            Container(
              padding: const EdgeInsets.symmetric(vertical: Sizes.default15),
              alignment: Alignment.center,
              child: Text(
                '呼叫客服',
                style: StylesUtils.customTextStyle(
                    color: ColorsUtils.color000, fontSize: Sizes.default18),
              ),
            ),
            Container(
              padding: const EdgeInsets.only(bottom: Sizes.default15),
              alignment: Alignment.center,
              child: Text(
                '0779523151',
                style: StylesUtils.customTextStyle(
                    color: ColorsUtils.color515, fontSize: Sizes.default15),
              ),
            ),
          ],
        ),
        actionsWidget: [
          Container(
              alignment: Alignment.center,
              child: TextButton(
                onPressed: () {
                  Navigator.pop(context, 0);
                },
                child: Text(
                  '取消',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color333, fontSize: Sizes.default16),
                ),
              )),
          Container(
              alignment: Alignment.center,
              child: TextButton(
                onPressed: () {
                  Navigator.pop(context, 1);
                },
                child: Text('呼叫',
                    style: StylesUtils.customTextStyle(
                        fontSize: Sizes.default16, color: ColorsUtils.colorFf6)),
              ))
        ],
        themeData: BrnDialogConfig(
            dialogWidth: 280,
            radius: Sizes.default10,
            titlePaddingSm: EdgeInsets.zero,
            titlePaddingLg: EdgeInsets.zero,
            contentPaddingSm: EdgeInsets.zero,
            contentPaddingLg: EdgeInsets.zero,
            contentTextAlign: TextAlign.center));
    int? result = await showDialog<int>(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) {
        return dialog;
      },
    );
    if (result == 1) {
      /// 拨打电话
      launchPhone('10086');
    }
  }

  void launchPhone(String phoneNumber) async {
    String url = 'tel:$phoneNumber';
    Uri uri = Uri.parse(url);
    await launchUrl(uri);
  }
}
